package com.pktechan.api.activeMq;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Service;

import javax.jms.Destination;
import javax.jms.Queue;
import javax.jms.Topic;

/**
 * @program: cloudfloating
 * @description: 发送消息通用类
 * @author: qx.zhang
 * @create: 2021-03-12 15:29
 **/
@Service("activeMQSendService")
public class ActiveMQSendService {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Autowired
    private Queue sendMiniMessageQueueName;

    @Autowired
    private Topic sendMiniMessageTopicName;

    /**
     * 发送小程序消息到队列中
     *
     * @param message
     * @return
     */
    public void sendMiniMessageQueue(String message) {
        logger.debug("（20240604后，不发送MQ）发送消息到队列:{}", sendMiniMessageQueueName.toString());
//        this.sendMessage(this.sendMiniMessageQueueName, message);
    }

    /**
     * 发送小程序消息到队列中
     *
     * @param message
     * @return
     */
    public void sendMiniMessageTopic(String message) {
        this.sendMessage(this.sendMiniMessageTopicName, message);
    }


    // 发送消息，destination是发送到的队列，message是待发送的消息
    private void sendMessage(Destination destination, final String message) {
        logger.debug("（20240604后，不发送MQ）发送消息到队列:{}", destination.toString());
        jmsMessagingTemplate.convertAndSend(destination, message);
    }

}
